<template>
	<view class="pageItem">
		<block v-if="language">
			<web-view class="videoItem" :src="'/static/video_h5/index.html?lang='+language" @message="onPostMessage"></web-view>
		</block>
	</view>
</template>

<script>
	import {mapState} from 'vuex';
	export default {
		data() {
			return {
				language:''
			}
		},
		onLoad() {
			this.language = uni.getLocale();
			uni.$on('postMessage', this.onPostMessage);
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		onHide() {
			const
			    _funName = 'msgFromUniapp',
			    _data = {
			        msg: '隐藏了'
			    };
			const currentWebview = this.$scope.$getAppWebview().children()[0];
			currentWebview.evalJS(`${_funName}(${JSON.stringify(_data)})`);
		},
		onUnload() {
		    uni.$off('postMessage', this.onPostMessage);
		},
		methods:{
			onPostMessage(event){
				//console.log('查看App data')
				console.log(event)
				
				let pid = event.detail.data[0].play_id;			
				let uid = 0;
				if(this.hasLogin){
					uid = this.userInfo.id;
				}
				let token = uni.getStorageSync('token')??''; 
				// #ifdef APP
				let path = '/pages/popular/shortDetail?id='+pid;
				// #endif
				// #ifdef H5
				let path = '/pages/popular/shortDetail_h5?id='+pid;
				// #endif
				// console.log(path);
				this.$r(path);
				
			}
		}
	}
</script>
<style>
page{
	background: #000000;
}
</style>
<style lang="scss">
.pageItem{
	padding: 0;
	padding-top: var(--status-bar-height);
}
.videoItem{
	width: 100vw;
	height: calc(100vh - 50px - var(--status-bar-height));
	position: fixed;
	z-index: 90;
}
</style>
